# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=doxygen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.8.10
pkgrel=2
pkgdesc="A documentation system for C++, C, Java, IDL and PHP (mingw-w64)"
arch=('any')
url="http://www.doxygen.org/"
options=('strip' 'staticlibs')
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-sqlite3")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python2"
             #"${MINGW_PACKAGE_PREFIX}-qt4"
             'flex'
             'bison')
optdepends=("${MINGW_PACKAGE_PREFIX}-qt4")
source=("http://ftp.stack.nl/pub/users/dimitri/${_realname}-${pkgver}.src.tar.gz"
        'cmake-mingw.patch'
        'fix-casts.patch')
sha256sums=('cedf78f6d213226464784ecb999b54515c97eab8a2f9b82514292f837cf88b93'
            'f900c155a5b8a8988c5312b8e3e2820407c16f5acb1f30a6ae34a2fa40915201'
            '0cbf92d80e757287bfe1bb86168751de8a467e31e8ed26baf7c2b75450ce1f4c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/cmake-mingw.patch"
  patch -p1 -i "${srcdir}/fix-casts.patch"
}

build() {
  export QTDIR=${MINGW_PREFIX}

  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -Dbuild_wizard=OFF \
    -Dbuild_search=OFF \
    -Duse_sqlite3=ON \
    -Duse_libclang=OFF \
    ../${_realname}-${pkgver}
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}

  make DESTDIR="${pkgdir}" install
}
